﻿#region Imports
using System;
using System.Media;
using CommonUtilities.Enums;
using CommonUtilities.Extensions;
using CommonUtilities.Properties;
#endregion

namespace CommonUtilities.Util
{
    public static class Notifications
    {
        public static void PlaySound(eNotificationSound sound, bool isMute, bool playAsync = true)
        {
            try
            {
                if (isMute) throw new Exception();

                string fileName = "";
                SoundPlayer plyr = new SoundPlayer();

                switch (sound)
                {
                    case eNotificationSound.Start:
                        plyr.Stream = Resources.Media_StartUp;
                        break;

                    case eNotificationSound.Cleanup:
                        plyr.Stream = Resources.Media_Recycle;
                        break;

                    case eNotificationSound.WindowState:
                        plyr.Stream = Resources.Media_Restore;
                        break;

                    case eNotificationSound.Exit:
                        playAsync = false;
                        plyr.Stream = Resources.Media_ShutDown;
                        break;

                    case eNotificationSound.LogOff:
                        playAsync = false;
                        plyr.Stream = Resources.Media_LogOff;
                        break;

                    default:
                        break;
                }

                if (plyr.Stream.IsNull()) throw new Exception();
                if (playAsync) plyr.Play(); else plyr.PlaySync();
                plyr = null;
            }
            catch (Exception ex)
            {
                // No sound
            }
        }
    }
}
